#include "Tests.h"
#include "BubbleSort.h"
#include "SelectionSort.h"
#include "InsertionSort.h"
#include "MergeSort.h"
#include "QuickSort.h"
using namespace std;
void Tests::testAlgorithms(long *data, long n, bool sig)
{
    this -> a(data, n);
    this -> b(data, n);
    this -> c(data, n);
    this -> d(data, n);
    if (sig)    // It seems that, from unknown reasons (for the moment), QuickSort crashes on the worst case test. :(
        this -> e(data, n);
}
void Tests::a(long *data, long n)
{
    BubbleSort A = BubbleSort(data, n);
    double t = A.getExecutionTime(n);
    cout << "BubbleSort does it in " << t << " seconds.";
    if (A.Check(n))
        cout << "\tok.";
    else
        cout << "\tnot ok.";
    cout << "\n";
    FILE *fp = fopen("Results.txt", "a");
    fprintf(fp, "\n%ld\t%f", n, t);
    fclose(fp);
}
void Tests::b(long *data, long n)
{
    SelectionSort B = SelectionSort(data, n);
    double t = B.getExecutionTime(n);
    cout << "SelectionSort does it in " << t << " seconds.";
    if (B.Check(n))
        cout << "\tok.";
    else
        cout << "\tnot ok.";
    cout << "\n";
    FILE *fp = fopen("Results.txt", "a");
    fprintf(fp, "\t%f", t);
    fclose(fp);
}
void Tests::c(long *data, long n)
{
    InsertionSort C = InsertionSort(data, n);
    double t = C.getExecutionTime(n);
    cout << "InsertionSort does it in " << t << " seconds.";
    if (C.Check(n))
        cout << "\tok.";
    else
        cout << "\tnot ok.";
    cout << "\n";
    FILE *fp = fopen("Results.txt", "a");
    fprintf(fp, "\t%f", t);
    fclose(fp);
}
void Tests::d(long *data, long n)
{
    MergeSort D = MergeSort(data, n);
    double t = D.getExecutionTime(n);
    cout << "MergeSort does it in " << t << " seconds.";
    if (D.Check(n))
        cout << "\tok.";
    else
        cout << "\tnot ok.";
    cout << "\n";
    FILE *fp = fopen("Results.txt", "a");
    fprintf(fp, "\t%f", t);
    fclose(fp);
}
void Tests::e(long *data, long n)
{
    QuickSort E = QuickSort(data, n);
    double t = E.getExecutionTime(n);
    cout << "QuickSort does it in " << t << " seconds.";
    if (E.Check(n))
        cout << "\tok.";
    else
        cout << "\tnot ok.";
    cout << "\n";
    FILE *fp = fopen("Results.txt", "a");
    fprintf(fp, "\t%f", t);
    fclose(fp);
}

